package com.jcodecraeer.xrecyclerview.progressindicator.indicator;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;

import java.util.ArrayList;
import java.util.List;

public class BallScaleRippleIndicator extends BallScaleIndicator {
    @Override
    public void draw(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.STROKE_STYLE);
        paint.setStrokeWidth(3);
        super.draw(canvas, paint);
    }

    @Override
    public List<Animator> createAnimation() {
        List<Animator> animators=new ArrayList<>();
        AnimatorValue scaleAnim = new AnimatorValue();
        scaleAnim.setCurveType(Animator.CurveType.SMOOTH_STEP);
        scaleAnim.setDuration(1000);
        scaleAnim.setLoopedCount(-1);
        scaleAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                scale =v;
                postInvalidate();
            }
        });
        scaleAnim.start();

        AnimatorValue alphaAnim = new AnimatorValue();
        alphaAnim.setCurveType(Animator.CurveType.SMOOTH_STEP);
        alphaAnim.setDuration(1000);
        alphaAnim.setLoopedCount(-1);
        alphaAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                alpha = (int)v;
                postInvalidate();
            }
        });
        alphaAnim.start();
        animators.add(scaleAnim);
        animators.add(alphaAnim);
        return animators;
    }
}
